package com.fileuptool.controller;

import java.io.IOException;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import com.fileuptool.service.FileDownService;

import io.swagger.annotations.ApiOperation;

/**
* 
* @author dinghao
* @ClassName: FileDownController 
* @Description: TODO
* @date 2018年3月15日 下午4:39:56 
*
 */
@RestController
public class FileDownController {

	@Autowired
	private FileDownService fileDownService;
	
	@GetMapping("/getFile/{filename}/{filetype}")
	@ApiOperation("文件下载图片时需要将请求路径复制到浏览器上访问")
	public ResponseEntity<byte[]> getFile(@PathVariable String filename,@PathVariable String filetype) {
		try {
			return fileDownService.getFile(filename,filetype);
		} catch (IOException e) {
			e.printStackTrace();
			return null;
		}
	}
	
	@GetMapping("/getFile2/{filename}/{filetype}")
	@ApiOperation("文件下载到指定路径")
	public String getFile2(@PathVariable String filename,@PathVariable String filetype) {
		try {
			return fileDownService.getFile2(filename,filetype);
		} catch (Exception e) {
			e.printStackTrace();
			return "文件下载失败!";
		}
	}
	
}
